package com.tianyadu.security.core.authentication;

import com.tianyadu.security.core.properties.propertieVO.SecurityConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;

/**
 * @FileName: AbstractChannelSecurityConfig
 * @Description:
 * @author: xueyj
 * @create: 2018-12-13 23:06
 */
public class AbstractChannelSecurityConfig extends WebSecurityConfigurerAdapter {

    /** 认证成功处理器 */
    @Autowired
    protected AuthenticationSuccessHandler authSuccessHandler;

    /** 认证失败处理器 */
    @Autowired
    protected AuthenticationFailureHandler authFailureHandler;

    /**
      * @Description: 配置用户名密码登陆认证信息
      * @param:
      * @return:
      * @author:
      * @date:   2018/12/14 11:35
      */
    protected void applyPasswordAuthenticationConfig(HttpSecurity http) throws Exception {
        http.formLogin()
                .loginPage(SecurityConstants.DEFAULT_UNAUTHENTICATION_URL)
                .loginProcessingUrl(SecurityConstants.DEFAULT_LOGIN_PROCESSING_URL_FORM)
                .successHandler(authSuccessHandler)
                .failureHandler(authFailureHandler);
    }

}